<?php

namespace app\controller\admin\calendar;

use app\model\admin\calendar\CalendarLabel;
use laytp\controller\Backend;
use laytp\library\CommonFun;
use think\facade\Db;

/**
 * Class Career
 * @package app\controller\admin\ah
 */
class Label extends Backend
{
    protected $model;
    protected $gameId;
    protected $noNeedAuth = ['index', 'info'];
    public function initialize()
    {
//        $action = $this->request;

        $this->model = new CalendarLabel();
        parent::initialize(); // TODO: Change the autogenerated stub
    }

    //添加
    public function add()
    {
        if(!$this->request->param("game_id")){
            return $this->error("缺少游戏id");
        }
        $gameId = $this->request->param("game_id");
        $post = CommonFun::filterPostData($this->request->post());
        try{
            $post['relation_id'] = $gameId;
            if ($this->model->create($post)) {
                $this->clearCache();
                return $this->success('添加成功', $post);
            } else {
                return $this->error('操作失败');
            }
        } catch (\Exception $e) {
            return $this->exceptionError($e);
        }
    }
}